package com.gxa.service.impl;

import com.gxa.common.PaginationResult;
import com.gxa.mapper.CustomerMapper;
import com.gxa.pojo.MemberDis;
import com.gxa.pojo.MembershipCard;
import com.gxa.pojo.MembershipCardType;
import com.gxa.service.CustomerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * Created with IntelliJ IDEA.
 * User: zrf
 * Date: 2020/10/29 9:42
 * Description:
 * Version: V1.0
 */
@Service
public class CustomerServiceImpl implements CustomerService {

    @Autowired(required = false)
    private CustomerMapper customerMapper;

    /**
     * 查询所有客户信息
     *
     * @param currentPage,pageSize
     * @return 实例对象
     */
    @Override
    public PaginationResult selCustom(Integer currentPage, Integer pageSize) {
        PaginationResult paginationResult = new PaginationResult();
        int parm1 = (currentPage - 1) * pageSize;
        paginationResult.setData(customerMapper.selAnn(parm1,pageSize));
        paginationResult.setCurrentPage(parm1);
        paginationResult.setPageSize(pageSize);
        int total = cusCont() / pageSize;
        System.out.println(cusCont());
        if(cusCont() % pageSize != 0){
            total+=1;
        }
        System.out.println(total);
        paginationResult.setTotalPage(total);
        paginationResult.setTotalSize(cusCont());
        return paginationResult;
    }

    /**
     * 查询所有会员卡信息
     *
     * @param currentPage,pageSize
     * @return 实例对象
     */
    @Override
    public PaginationResult seleMember(Integer currentPage, Integer pageSize) {
        PaginationResult paginationResult = new PaginationResult();
        int parm1 = (currentPage - 1) * pageSize;
        paginationResult.setData(customerMapper.seleMember(parm1,pageSize));
        paginationResult.setCurrentPage(parm1);
        paginationResult.setPageSize(pageSize);
        int total = memberCont() / pageSize;
        System.out.println(memberCont());
        if(memberCont() % pageSize != 0){
            total+=1;
        }
        System.out.println(total);
        paginationResult.setTotalPage(total);
        paginationResult.setTotalSize(memberCont());
        return paginationResult;
    }

    /**
     * 添加会员
     *
     * @param membershipCard
     * @return 实例对象
     */
    @Override
    public int addCustom(MembershipCard membershipCard) {
        return customerMapper.addCustom(membershipCard);
    }

    /**
     * 编辑会员
     *
     * @param membershipCard
     * @return 实例对象
     */
    @Override
    public int updateCustom(MembershipCard membershipCard) {
        return customerMapper.updateCustom(membershipCard);
    }

    /**
     * 会员升级
     *
     * @param membershipCard
     * @return 实例对象
     */
    @Override
    public int updateMembershipCard(MembershipCard membershipCard) {
        return customerMapper.updateMembershipCard(membershipCard);
    }
    /**
     * 删除会员
     *
     * @param memberId
     * @return 实例对象
     */
    @Override
    public int delCupro(Integer memberId) {
        return customerMapper.delCupro(memberId);
    }

    @Override
    public List<Map> selMem(Integer memberId) {
        return customerMapper.selMem(memberId);
    }

    @Override
    public int addMember(MembershipCardType membershipCardType) {
        return customerMapper.addMember(membershipCardType);
    }

    /**
     * 编辑会员卡类型信息
     *
     * @param membershipCardType
     * @return 实例对象
     */
    @Override
    public int updateMemb(MembershipCardType membershipCardType) {
        return customerMapper.updateMemb(membershipCardType);
    }

    /**
     * 删除会员卡类型信息
     *
     * @param membershipCardId
     * @return 实例对象
     */
    @Override
    public int delMemb(Integer membershipCardId) {
        return customerMapper.delMemb(membershipCardId);
    }

//    /**
//     * 查询会员折扣
//     *
//     * @param currentPage,pageSize
//     * @return 实例对象
//     */
//    @Override
//    public PaginationResult queryMemDis(Integer currentPage, Integer pageSize) {
//        PaginationResult paginationResult = new PaginationResult();
//        int parm1 = (currentPage - 1) * pageSize;
//        paginationResult.setData(customerMapper.queryMemDis(parm1,pageSize));
//        paginationResult.setCurrentPage(parm1);
//        paginationResult.setPageSize(pageSize);
//        int total = membDisCont() / pageSize;
//        System.out.println(membDisCont());
//        if(membDisCont() % pageSize != 0){
//            total+=1;
//        }
//        System.out.println(total);
//        paginationResult.setTotalPage(total);
//        paginationResult.setTotalSize(membDisCont());
//        return paginationResult;
//    }

//    /**
//     * 根据会员类型查询会员折扣
//     *
//     * @param memberType
//     * @return 实例对象
//     */
//    @Override
//    public Map selectMemb(String memberType) {
//        return customerMapper.selectMemb(memberType);
//    }

//    /**
//     * 编辑会员折扣
//     *
//     * @param memberDis
//     * @return 实例对象
//     */
//    @Override
//    public int updateMemberDis(MemberDis memberDis) {
//        return customerMapper.updateMemberDis(memberDis);
//    }
    /**
     * 查询会员类型
     *
     * @param
     * @return 实例对象
     */
    @Override
    public List<Map> selMembTyp() {
        return customerMapper.selMembTyp();
    }

    /**
     * 查询开卡门店
     *
     * @param
     * @return 实例对象
     */
    @Override
    public List<Map> selBreach() {
        return customerMapper.selBreach();
    }

//    private int membDisCont() {
//        return customerMapper.membDisCont();
//    }

    public int cusCont(){
        return customerMapper.cusCont();
    }

    public int memberCont(){
        return customerMapper.memberCont();
    }
}
